package cn.tedu;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Demo06 {
    public static void main(String[] args) {
        while (true) {
            Scanner scan = new Scanner(System.in);
            System.out.println("请输入英雄名");
            String name = scan.nextLine();

            if("exit".equalsIgnoreCase(name)){
                return;
            }

            System.out.println("请输入价格");
            double money = scan.nextDouble();

            try (Connection conn = DBUtils.getConn();) {
                Statement s = conn.createStatement();
                int a = s.executeUpdate("insert into hero(name,money) values('" + name + "','" + money + "')");

                System.out.println("创建完毕!" + "总共: " + a + "条数据");
                ResultSet rl = s.executeQuery("select * from hero");
                while (rl.next()) {
                    int id = rl.getInt(1);
                    String n = rl.getString(2);
                    double m = rl.getDouble(3);
                    System.out.println(id + "\t" + n + "\t" + m);
                }
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
    }
}
